package com.py.credit.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.py.credit.service.XypjRemoteBaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.Cards;
import com.py.credit.entity.DictDetailEntity;
import com.py.credit.entity.Enterprise;
import com.py.credit.entity.SysMsgDetailEntity;
import com.py.credit.entity.SysMsgEntity;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.common.OptionalColumn;
import com.py.credit.entity.enums.CardsEnum;
import com.py.credit.entity.enums.EnterpriseEnum;
import com.py.credit.service.CardsService;
import com.py.credit.service.MsgService;
import com.py.credit.service.SysDictService;
import com.py.credit.utils.EmailUtil;
import com.py.credit.utils.ExcelUtil;
import com.py.credit.utils.MapCache;
import com.py.framework.core.common.Page;
import com.py.framework.core.helper.HttpServletHelper;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "/card")
public class CardsController {
	@Autowired
	private CardsService cardsService;
	@Autowired
	private XypjRemoteBaseService xypjRemoteBaseService;
	@Autowired
	private MsgService msgService;

	@Autowired
	private SysDictService sysDictService;

	@Value("${platformUrl}")
	private String Eurl;

	private static String FRONT_TABLE_ID = "cards";

	private static String FRONT_ENTER_TABLE_ID = "enterprise";

	@RequestMapping(value = "/getEnterpriseForPage")
	@ApiOperation(value = "查询申报企业信息(在显示主体信息的界面调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "mainName", value = "主体名称", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "mainType", value = "主体类型", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "zzzt", value = "证照状态", required = true) })
	public RestServiceResult<List<LinkedHashMap<String, Object>>> getEnterpriseForPage(
			@RequestParam(value = "mainName", defaultValue = "") String mainName,
			@RequestParam(value = "mainType", defaultValue = "") String mainType,
			@RequestParam(value = "zzzt", defaultValue = "") String zzzt,
			@RequestParam(value = "condition", defaultValue = "") String condition, Page page,
			HttpServletRequest request) {

		String token = HttpServletHelper.getUserToken(request);
		RestServiceResult<List<LinkedHashMap<String, Object>>> result = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(token);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}

		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_ENTER_TABLE_ID);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? EnterpriseEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		// condition="[{columnEN:\"batch_id\",value:\"EX-test-1-20180326-1174\",type:\"varchar\",fuzzy:fasle}]";
		RestServiceResult<List<LinkedHashMap<String, Object>>> r = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		try {
			List<LinkedHashMap<String, Object>> tableList = cardsService.selectEnterpriseForPage(mainName, mainType,
					zzzt, showColumns, new String[] { "userId" }, condition, page);
			r.setData(tableList);
			r.setCount(page.getTotalCount());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("查询申报企业信息失败！");
		}
		return r;

	}

	@RequestMapping(value = "/exportEnterprise.json")
	@ApiOperation(value = "导出申报企业信息(在显示主体信息的界面调用)", httpMethod = "GET", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "mainName", value = "主体名称", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "mainType", value = "主体类型", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "zzzt", value = "证照状态", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "columnEN", value = "字段名英文", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "condition", value = "参数字符", required = true) })
	public RestServiceResult<List<LinkedHashMap<String, Object>>> exportEnterprise(
			@RequestParam(value = "mainName", defaultValue = "") String mainName,
			@RequestParam(value = "mainType", defaultValue = "") String mainType,
			@RequestParam(value = "zzzt", defaultValue = "") String zzzt,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletResponse response, HttpServletRequest request) {
		page.setLimit(1000);
		List<String> showColumns = JSONArray.parseArray(columnEN, String.class);
		List<OptionalColumn> optionalColumns = EnterpriseEnum.getOptionalColumns();
		List<LinkedHashMap<String, Object>> data;
		RestServiceResult<List<LinkedHashMap<String, Object>>> result = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#getAchievementCount", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		try {
			data = cardsService.selectEnterpriseForPage(mainName, mainType, zzzt, showColumns, null, condition, page);
			if (RestServiceResult.CODE_SUCCESS != result.getCode()) {
				return result;
			}
			ExcelUtil.downloadLinkExcel(response, data, "申报企业信息领取列表", "申报企业信息领取列表", showColumns, optionalColumns);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("申报企业信息报告领取导出异常，请稍后再试！");
			ExceptionLogger.error("申报企业信息报告领取导出异常！", e.getMessage(), e);
			return result;
		}
	}

	@RequestMapping(value = "/getEnterpriseAdvancedConditionColumns.json")
	@ApiOperation(value = "申报企业的高级查询(在显示主体信息的界面调用)", produces = "application/json")
	public RestServiceResult<List<OptionalColumn>> getEnterpriseAdvancedConditionColumns() {
		RestServiceResult<List<OptionalColumn>> r = new RestServiceResult<List<OptionalColumn>>();
		try {
			r = new RestServiceResult<List<OptionalColumn>>(EnterpriseEnum.getAdvancedConditionColumns());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("申报企业的高级查询");
		}
		return r;
	}

	@RequestMapping(value = "/addEnterpriseShowColunms.json")
	@ApiOperation(value = "获取申报企业展示字段(在显示主体信息的界面调用)", httpMethod = "GET", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "columns", value = "字段集合", required = true) })
	public RestServiceResult<String> addEnterpriseShowColunms(
			@RequestParam(value = "columns", required = true) String[] columns, HttpServletRequest request) {
		RestServiceResult<String> result = new RestServiceResult<String>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#addShowColunms", "未获取到当前用户信息！");
				return result;
			}
			String column = StringUtils.join(columns, ",");
			MapCache.set(userInfo.getId() + "_" + FRONT_ENTER_TABLE_ID, StringUtils.split(column, ","));
		} else {
			result.setCode(user.getCode());
			result.setMsg("获取申报企业展示字段失败！");
			return result;
		}
		return new RestServiceResult<String>();
	}

	@RequestMapping(value = "/add")
	public RestServiceResult<Object> add(@RequestBody Cards card) {
		RestServiceResult<Object> r = new RestServiceResult<Object>();
		// Cards card1 = new Cards();
		// card1.setCardName("小李子");
		// card1.setCardPlace("D:/");
		// card1.setCardType("身份证");
		// card1.setCardZt("正常");
		// card1.setIdCard("2937864928293");
		// card1.setQsrq("2018-1-1");
		// card1.setStatus("1");
		// card1.setTybm("1");
		// card1.setZzrq("2020-1-1");
		// card1.setShzt("已审核");
		try {
			cardsService.add(card);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("证照添加失败！");
		}
		return r;

	}

	@RequestMapping(value = "/addReportEnterprise")
	@ApiOperation(value = "添加申报企业信息(在企业填写证照类指标时调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "Enterprise", name = "enterprise", value = "申报企业信息", required = true) })
	public RestServiceResult<Object> addReportEnterprise(@RequestBody Enterprise enterprise) {
		RestServiceResult<Object> r = new RestServiceResult<Object>();
		try {
			cardsService.addReportEnterprise(enterprise);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("添加申报企业失败！");
		}
		return r;

	}

	@RequestMapping(value = "/edit")
	public RestServiceResult<Object> edit(String id, String zjName, String startTime, String endTime) {
		RestServiceResult<Object> r = new RestServiceResult<Object>();
		try {
			Cards card = new Cards();
			card.setId(id);
			card.setZjName(zjName);
			card.setStartTime(startTime);
			card.setEndTime(endTime);
			cardsService.edit(card);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("修改证照失败！");
		}
		return r;

	}

	@RequestMapping(value = "/delete")
	@ApiOperation(value = "删除证照(在用户前台界面调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "List<String>", name = "cardIds", value = "证照ID", required = true) })
	public RestServiceResult<Object> delete(@RequestParam(value = "cardIds", defaultValue = "") List<String> cardIds) {
		RestServiceResult<Object> r = new RestServiceResult<Object>();
		try {
			cardsService.delete(cardIds);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("删除证照失败！");
		}
		return r;

	}

	@RequestMapping(value = "/getCardsInfoForPage")
	@ApiOperation(value = "查询证照信息(在后台证照显示的界面调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "zjName", value = "证照名称", required = false),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "userId", value = "用户id", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "sign", value = "标记", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "type", value = "证照类型", required = true) })
	public RestServiceResult<List<LinkedHashMap<String, Object>>> getCardsInfo(
			@RequestParam(value = "cardName", defaultValue = "") String zjName,
			@RequestParam(value = "cardType", defaultValue = "") String type,
			@RequestParam(value = "userId", defaultValue = "") String userId,
			@RequestParam(value = "sign", defaultValue = "") String sign,
			@RequestParam(value = "condition", defaultValue = "") String condition, Page page,
			HttpServletRequest request) {
		String token = HttpServletHelper.getUserToken(request);
		RestServiceResult<List<LinkedHashMap<String, Object>>> result = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(token);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}

		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? CardsEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		// condition="[{columnEN:\"batch_id\",value:\"EX-test-1-20180326-1174\",type:\"varchar\",fuzzy:fasle}]";
		RestServiceResult<List<LinkedHashMap<String, Object>>> r = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		try {
			List<LinkedHashMap<String, Object>> tableList = cardsService.selectCardsInfoForPage(zjName, type, userId,
					sign, showColumns, new String[] { "id", "filePath", "idCard", "shsj", "collectTime", "zjName" },
					condition, page);
			r = new RestServiceResult<List<LinkedHashMap<String, Object>>>(page.getTotalCount(), tableList);
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("查询证照信息失败！");
		}
		return r;

	}

	@RequestMapping(value = "/exportCards.json")
	@ApiOperation(value = "导出证照信息(在后台证照显示的界面调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "cardName", value = "主体名称", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "cardType", value = "主体类型", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "userId", value = "用户id", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "sign", value = "标记", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "columnEN", value = "字段名英文", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "condition", value = "参数字符", required = true) })
	public RestServiceResult<List<LinkedHashMap<String, Object>>> exportCards(
			@RequestParam(value = "cardName", defaultValue = "") String cardName,
			@RequestParam(value = "cardType", defaultValue = "") String cardType,
			@RequestParam(value = "userId", defaultValue = "") String userId,
			@RequestParam(value = "sign", defaultValue = "") String sign,
			@RequestParam(value = "columnEN", defaultValue = "", required = true) String columnEN,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletResponse response, HttpServletRequest request) {
		page.setLimit(1000);
		List<String> showColumns = JSONArray.parseArray(columnEN, String.class);
		List<OptionalColumn> optionalColumns = CardsEnum.getOptionalColumns();
		List<LinkedHashMap<String, Object>> data;
		RestServiceResult<List<LinkedHashMap<String, Object>>> result = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#getAchievementCount", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		try {
			data = cardsService.selectCardsInfoForPage(cardName, cardType, userId, sign, showColumns, null, condition,
					page);
			if (RestServiceResult.CODE_SUCCESS != result.getCode()) {
				return result;
			}
			ExcelUtil.downloadLinkExcel(response, data, "证照领取列表", "证照领取列表", showColumns, optionalColumns);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("报告领取导出异常，请稍后再试！");
			ExceptionLogger.error("报告领取导出异常！", e.getMessage(), e);
			return result;
		}
	}

	@RequestMapping(value = "/getCardsAdvancedConditionColumns.json")
	@ApiOperation(value = "证照的高级查询(在后台证照显示的界面调用)", produces = "application/json")
	public RestServiceResult<List<OptionalColumn>> getCardsAdvancedConditionColumns() {
		RestServiceResult<List<OptionalColumn>> r = new RestServiceResult<List<OptionalColumn>>();
		try {
			r = new RestServiceResult<List<OptionalColumn>>(CardsEnum.getAdvancedConditionColumns());
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("证照的高级查询失败！");
		}
		return r;
	}

	@RequestMapping(value = "/addCardsShowColunms.json")
	@ApiOperation(value = "获取证照展示字段(在后台证照显示的界面调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "columns", value = "字段集合", required = true) })
	public RestServiceResult<String> addCardsShowColunms(
			@RequestParam(value = "columns", required = true) String[] columns, HttpServletRequest request) {
		RestServiceResult<String> result = new RestServiceResult<String>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#addShowColunms", "未获取到当前用户信息！");
				return result;
			}
			String column = StringUtils.join(columns, ",");
			MapCache.set(userInfo.getId() + "_" + FRONT_TABLE_ID, StringUtils.split(column, ","));
		} else {
			result.setCode(user.getCode());
			result.setMsg("获取证照展示字段失败！");
			return result;
		}
		return new RestServiceResult<String>();
	}

	@RequestMapping(value = "/getCardsDetail")
	@ApiOperation(value = "查询证照详情(在点击查看详情时调用)", produces = "application/json")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "证照id", required = true),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "userId", value = "标记", required = false),
			@ApiImplicitParam(paramType = "query", dataType = "String", name = "type", value = "类型", required = false) })
	public RestServiceResult<List<LinkedHashMap<String, Object>>> getCardsDetail(
			@RequestParam(value = "userid", defaultValue = "") String id,
			@RequestParam(value = "type", defaultValue = "") String type) {
		RestServiceResult<List<LinkedHashMap<String, Object>>> r = new RestServiceResult<List<LinkedHashMap<String, Object>>>();
		try {
			r.setData(cardsService.selectHistory(id));
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("查询证照详情失败！");
		}
		return r;

	}

	@RequestMapping(value = "/editCardShzj.do")
	public RestServiceResult<Object> editCardShzj(@RequestParam(value = "shzt", defaultValue = "") String shzt,
			@RequestParam(value = "bz", defaultValue = "") String bz,
			@RequestParam(value = "id", defaultValue = "") long id,
			@RequestParam(value = "startTime", defaultValue = "") String startTime,
			@RequestParam(value = "endTime", defaultValue = "") String endTime, HttpServletRequest request) {
		RestServiceResult<Object> r = new RestServiceResult<Object>();
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				r.setCode(RestServiceResult.CODE_UNKNOW);
				r.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("AchievementController#addShowColunms", "未获取到当前用户信息！");
				return r;
			}
		}
		try {
			String shr = userInfo.getUsername();
			String cardId = String.valueOf(id);
			Cards card = new Cards();
			card.setId(cardId);
			card.setStartTime(startTime);
			card.setEndTime(endTime);
			cardsService.edit(card);
			cardsService.updateCardShzj(cardId, shzt);
			cardsService.addHistory(shr, bz, id, shzt, "证照审核中心");
			Map<String, Object> map = cardsService.selectUserinfo(cardId);
			String userType = "";
			if (map.get("type").equals("C")) {
				userType = "企业";
			}
			if (map.get("type").equals("P")) {
				userType = "个人";
			}
			Cards cards = cardsService.selectCardsDetail(String.valueOf(id), null, null, null, null);
			List<DictDetailEntity> list = sysDictService.getDictDetails("ZJLX", cards.gettype());
			if (shzt.equals("1")) {
				Map<String, Object> model = new HashMap<String, Object>();
				model.put("userType", userType);
				model.put("hello", "恭喜您！");
				model.put("userName", "证照审核");
				model.put("status", "通过");
				model.put("url", Eurl);
				EmailUtil.sendHtmlMessageByTemplate((String) map.get("dzyx"), "【大数据征信】证照审核", model,
						"nameAuthenticationTemplate.ftl");
				SysMsgEntity entity = new SysMsgEntity();
				List<SysMsgDetailEntity> detail = new ArrayList<>();
				SysMsgDetailEntity entity1 = new SysMsgDetailEntity();
				detail.add(entity1);
				entity1.setRevieverName((String) map.get("username"));
				Long CardId = (Long) map.get("id");
				entity1.setReviever(CardId);
				entity1.setRevieveType(1);
				entity.setMsgTitle("证照审核通知");
				entity.setMsgContent("【大数据征信平台】您有一个证照审核成功，类型为" + list.get(0).getDtlValue() + "请至证照管理界面点击“管理我的证照”查看");
				entity.setLinkUrl(Eurl);
				entity.setMsgType(1);
				entity.setDetails(detail);
				msgService.addMsgInfo(entity);
			}
			if (!shzt.equals("1")) {
				Map<String, Object> model = new HashMap<String, Object>();
				model.put("userType", userType);
				model.put("hello", "很抱歉，");
				model.put("userName", "证照审核");
				model.put("status", "未通过");
				model.put("url", Eurl);
				EmailUtil.sendHtmlMessageByTemplate((String) map.get("dzyx"), "【大数据征信】证照审核", model,
						"nameAuthenticationTemplate.ftl");
				SysMsgEntity entity = new SysMsgEntity();
				List<SysMsgDetailEntity> detail = new ArrayList<>();
				SysMsgDetailEntity entity1 = new SysMsgDetailEntity();
				detail.add(entity1);
				entity1.setRevieverName((String) map.get("username"));
				Long CardId = (Long) map.get("id");
				entity1.setReviever(CardId);
				entity1.setRevieveType(1);
				entity.setMsgTitle("证照审核通知");
				entity.setMsgContent("【大数据征信平台】您有一个证照审核失败，类型为" + list.get(0).getDtlValue() + "请至证照管理界面点击“管理我的证照”查看");
				entity.setLinkUrl(Eurl);
				entity.setMsgType(1);
				entity.setDetails(detail);
				msgService.addMsgInfo(entity);
			}
		} catch (Exception e) {
			r.setCode(RestServiceResult.CODE_UNKNOW);
			r.setMsg("修改证照状态！");
		}
		return r;
	}

	// @RequestMapping(value = "/getCount", method = RequestMethod.GET)
	// @ApiOperation(value = "查询证照是否绑定模型", httpMethod = "GET", produces =
	// "application/json")
	// @ApiImplicitParams({
	// @ApiImplicitParam(paramType = "query", dataType = "String", name =
	// "cardId", value = "证照id", required = true)
	// })
	// public RestServiceResult<Integer>
	// getCount(@RequestParam(value="cardId",defaultValue="") String cardId
	// ) {
	// RestServiceResult<Integer> r = new RestServiceResult<Integer>();
	// try {
	// r.setData(cardsService.selectCount(cardId));
	// } catch (Exception e) {
	// r.setCode(RestServiceResult.CODE_UNKNOW);
	// r.setMsg("查询证照详情失败！");
	// }
	// return r;
	//
	// }

	// @RequestMapping(value = "/getRootByName", method = RequestMethod.GET)
	// @ApiOperation(value = "校验证照审核权限", httpMethod = "GET", produces =
	// "application/json")
	// @ApiImplicitParams({
	// @ApiImplicitParam(paramType = "query", dataType = "String", name =
	// "name", value = "账号", required = true) })
	// public RestServiceResult<Cards> getRootByName(@RequestParam(value =
	// "name", required = false)String name) {
	//
	// return new RestServiceResult<Cards>();
	//
	// }

	// @RequestMapping(value = "/getModelInfo", method = RequestMethod.GET)
	// @ApiOperation(value = "查询模型信息", httpMethod = "GET", produces =
	// "application/json")
	// @ApiImplicitParams({
	// @ApiImplicitParam(paramType = "query", dataType = "String", name =
	// "name", value = "机构名称", required = true) })
	// public RestServiceResult<Model> getModelInfo(@RequestParam(value =
	// "name", required = false)String name) {
	//
	// return new RestServiceResult<Model>();
	//
	// }

	// @RequestMapping(value = "/getExistCards")
	// @ApiOperation(value = "获取是否存在该类证照(在前台调写证照类指标时调用)", httpMethod = "GET",
	// produces = "application/json")
	// public RestServiceResult<Cards> getExistCards(@RequestParam(value =
	// "cardType", required = false) String cardType,
	// @RequestParam(value = "tybm", required = false) String tybm) {
	// RestServiceResult<Cards> r = new RestServiceResult<Cards>();
	// try {
	// r.setData(cardsService.selectCardsDetail(null, "1",cardType,tybm,"2"));
	// } catch (Exception e) {
	// r.setCode(RestServiceResult.CODE_UNKNOW);
	// r.setMsg("获取是否存在该类证照失败！");
	// }
	// return r;
	// }

	// @RequestMapping(value = "/checkBindIndexAndCards", method =
	// RequestMethod.GET)
	// @ApiOperation(value = "核查证照是否审核通过(接口内部调)", httpMethod = "GET", produces =
	// "application/json")
	// @ApiImplicitParams({
	// @ApiImplicitParam(paramType = "query", dataType = "string", name =
	// "cardType", value = "证照类型", required = false) })
	// public RestServiceResult<Object>
	// checkBindIndexAndCards(@RequestParam(value = "cardType", required =
	// false) String cardType) {
	// return new RestServiceResult<Object>();
	// }

	// @RequestMapping(value = "/checkCardsTime", method = RequestMethod.GET)
	// @ApiOperation(value = "核查证照是否过期(接口内部调)", httpMethod = "GET", produces =
	// "application/json")
	// @ApiImplicitParams({
	// @ApiImplicitParam(paramType = "query", dataType = "string", name =
	// "cardType", value = "证照类型", required = false) })
	// @ApiImplicitParam(paramType = "query", dataType = "string", name =
	// "tybm", value = "统一编码", required = false)
	// public RestServiceResult<Object> checkCardsTime(@RequestParam(value =
	// "cardType", required = false) String cardType,
	// @RequestParam(value = "tybm", required = false) String tybm ) {
	// return new RestServiceResult<Object>();
	// }
}
